unit LoginUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, IBDatabase, IBCustomDataSet, Grids, DBGrids, RzDBGrid,
  RzStatus, RzButton, StdCtrls, Mask, RzEdit, main, settingsunit;

type
  TLoginForm = class(TForm)
    DataSource1: TDataSource;
    IBDataSet1: TIBDataSet;
    IBTransaction1: TIBTransaction;
    IBDatabase1: TIBDatabase;
    RzDBGrid1: TRzDBGrid;
    RzEdit1: TRzEdit;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn2: TRzBitBtn;
    RzVersionInfoStatus1: TRzVersionInfoStatus;
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  LoginForm: TLoginForm;

implementation
//  uses ;
{$R *.dfm}

procedure TLoginForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  IBTransaction1.Commit;
  IBDataSet1.Active:=false;
  IBDatabase1.Connected:=false;
end;

procedure TLoginForm.FormShow(Sender: TObject);
begin
  IBDatabase1.DatabaseName:=MainForm.CurrentParams.database;
    try
    IBDatabase1.Connected:=true;
  except
    Settings.ShowModal;
    Application.Terminate;
    exit;
  end;
  IBDatabase1.Connected:=true;
  IBDataSet1.Active:=true;
  IBDataSet1.Open;
  RzDBGrid1.Columns[2].Visible:=false;
  RzDBGrid1.Columns[1].Width:=110;
end;

procedure TLoginForm.RzBitBtn1Click(Sender: TObject);
begin
  If RzEdit1.Text='power' then MainForm.N9.Visible:=true;
  MainForm.CurrentParams.appuser:=IBDataSet1.FieldByName('U_name').AsString;
  MainForm.CurrentParams.appuserid:=IBDataSet1.FieldByName('U_ID').AsString;
  LoginForm.Close;
end;

procedure TLoginForm.RzBitBtn2Click(Sender: TObject);
begin
 // Application.Terminate;
 halt(0);
end;

end.
